package ks.server;

import ks.framework.interfaces.IAuthorization;
import ks.managers.icon.IconManager;
import ks.server.persist.PersistentPluginManager;
import ks.server.persist.PersistentUserManager;
import ks.managers.plugin.PluginManager;
import ks.managers.table.TableManager;
import ks.server.authorization.AuthorizationManager;
import ks.server.persist.PersistentIconManager;


/**
 * Enables any server-side entity to get access to the key managers that you will
 * be designing.
 * <p>
 * I've inserted the {@link IconManager}. You will need to add the ones that you envision. 
 * 
 * @author George Heineman
 * @author Harry Moreno
 */
public class ServerContext {

	/** These are (essentially) singleton instances. */
	static PersistentIconManager iconManager;
	
	/** UserManager singleton. */
	static PersistentUserManager userManager;
	
	/** Authorization manager. */
	static IAuthorization authManager;
	
	/** PluginManager singleton. */
	static PersistentPluginManager pluginManager;
	
	static TableManager tableManager;
	
	/** 
	 * Return IconManager. 
	 */
	public static PersistentIconManager getIconManager() {
		if (iconManager == null) {
			// for persistent lecture today: PersistentIconManager instead
			iconManager = new PersistentIconManager();
			//iconManager = new IconManager();
		}
		
		return iconManager;
	}

	/**
	 * Return Authentication manager responsible for bridging gap between
	 * the Framework and the UserManager.
	 */
	public static IAuthorization getAuthorizationManager() {
		if (authManager == null) {
			authManager = new AuthorizationManager();
		}
		
		return authManager;
	}
	
	
	/**
	 * Return UserManager.
	 */
	public static PersistentUserManager getUserManager() {
		if (userManager == null) {
			userManager = new PersistentUserManager();
		}
		
		return userManager;
	}
	
	/**
	 * Return PluginManger.
	 * @author Harry Moreno
	 */
	public static PersistentPluginManager getPluginManager(){
		if(pluginManager == null){
			pluginManager = new PersistentPluginManager();
		}
		return pluginManager;
	}
	
	/**
	 * Return TableManager
	 * 
	 * @return Christopher Page
	 */
	public static TableManager getTableManager() {
		if (tableManager == null) {
			tableManager = new TableManager();
		}
		return tableManager;
	}
}
